package com.partner.frame;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class Sendsms {
	
	private static String Url = "http://222.73.117.158/msg/HttpBatchSendSM";
	
	public static String send(String mobile,String mobile_code,String content){
		
		HttpClient client = new HttpClient(); 
		PostMethod method = new PostMethod(Url); 
		String stutacode ="" ;	
		client.getParams().setContentCharset("UTF-8");
		method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");
		//int mobile_code = (int)((Math.random()*9+1)*100000);
	    //String content = new String("您的验证码是："+mobile_code+",请不要把验证码泄露给其他人。"); 

		NameValuePair[] data = {//提交短信
			    new NameValuePair("account", "yindang1"), 
			    new NameValuePair("pswd", "Yindang123"), 
			    new NameValuePair("mobile", mobile), 
			    new NameValuePair("msg", content),
			    new NameValuePair("needstatus", "true"),
		};
		method.setRequestBody(data);		
		try {
			client.executeMethod(method);	
			String SubmitResult =method.getResponseBodyAsString();
			//System.out.println(SubmitResult);
			stutacode = SubmitResult.substring(15, 16);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		return stutacode ;
	}
	
	public static void main(String [] args) {
		
		HttpClient client = new HttpClient(); 
		PostMethod method = new PostMethod(Url); 
		String stutacode ="" ;	
		client.getParams().setContentCharset("UTF-8");
		method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

		
		int mobile_code = (int)((Math.random()*9+1)*100000);

	    String content = new String("您的注册验证码是："+mobile_code+",请完成注册"); 

		NameValuePair[] data = {//提交短信
			    new NameValuePair("account", "yindang1"), 
			    new NameValuePair("pswd", "Yindang123"), 
			    new NameValuePair("mobile", "18890395532"), 
			    new NameValuePair("msg", content),
			    new NameValuePair("needstatus", "true"),
		};
		method.setRequestBody(data);		
		try {
			client.executeMethod(method);	
			String SubmitResult =method.getResponseBodyAsString();
			String s = SubmitResult.substring(15, 16);
			System.out.println(s);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
	}
	
}